<!DOCTYPE html>
<%@ page errorPage="error/Error.jsp" contentType="text/html;charset=UTF-8"  import="com.mmp.main.util.*,com.mmp.common.util.*,com.mmp.main.entity.*,java.util.*"%>
<html dir="rtl">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

    <title>تكهين جهاز</title></head>
    <body> 
    <form action="<%=request.getContextPath()%>/DeviceScrappingProcess" method="post" enctype="multipart/form-data" name="form1">
      <table  class="layout_grid">
        <tr>
          <td colspan="2"><h1 class="page_title">شاشة تكهين جهاز</h1></td>
        </tr>
        <tr>
          <td colspan="2"><%@ include file="../DeviceOverview.jsp" %> </td>
        </tr>

        <tr>
          <td  class="side_label_top">حالة الجهاز : </td>
          <td><textarea name="deviceCondition" id="deviceCondition" required></textarea></td>
        </tr>
        <tr>
          <td  class="side_label_middle">اسباب التكهين : </td>
          <td>    
          <select id="scrappingReason" name="scrappingReason" required>
        <%
        if (request.getAttribute("reasons")!=null)
            for (LookupScrappingReason obj : (List <LookupScrappingReason>)request.getAttribute("reasons")){
        %>
            <option value="<%=obj.getId()%>"><%=obj.getName()%></option>
        <%}%>
        </select>
        </td>
        </tr>
        <tr>
          <td  class="side_label_top"> تقرير سبب التكهين  : </td>
          <td><input type="file" name="scrappingReasonReportUrl" id="scrappingReasonReportUrl" multiple <%=(deviceInfo.getLookupDeviceCategory().getId() != Enums.DB_MAPPING_DEVICE_CATEGORY.C.getDBId())?"class='requiredFile'":"" %>></td>
        </tr>
        <tr>
          <td  class="side_label_top"> التقرير النهائي   : </td>
          <td><input type="file" name="scrappingFinalReportUrl" id="scrappingFinalReportUrl" multiple class="requiredFile"></td>
        </tr>
        <tr>
          <td  class="side_label_middle">تاريخ التكهين : </td>
          <td><input type="text" name="scrappingDate" id="scrappingDate"  class="caldr" required></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="submit" name="button" id="button" value="اتمام العملية"></td>
        </tr>
      </table>
    </form>
    
    <%
 
    HospitalDeviceScrappingInfo scrapInfo = deviceInfo.getHospitalDeviceScrappingInfo();
    
    if (scrapInfo != null){
        String  deviceId = "" + deviceInfo.getId();
        String  deviceScrappingId  = "" + scrapInfo.getPkId() ;
        String  deviceCondition  = Common.getDisplayString(scrapInfo.getDeviceCondition() , ""); 
        
        String  scappingReason  = "";
        if(scrapInfo.getLookupScrappingReason() != null)
           scappingReason = "" + scrapInfo.getLookupScrappingReason().getId();
           
        String scrappingDate  = DateUtil.getDateString(scrapInfo.getScrappingDate());   
        
        String scrappingReasonFiles = scrapInfo.getScrappingReasonReportUrl();
        String scrappingFinalFiles = scrapInfo.getScrappingFinalReportUrl();
    %>
   <script>
   $(function(){
	   appendIdElement("deviceScrappingId","<%=deviceScrappingId%>");
	   setInnerHTML("deviceCondition","<%=deviceCondition%>");
	   setComboSelectedValue("scrappingReason","<%=scappingReason%>");
	   setDateValue("scrappingDate","<%=scrappingDate%>");
	   
	   showUploadedFilesList("scrappingReasonReportUrl", <%=HtmlUtil.arrayFromJavaToJavaScript(scrappingReasonFiles)%>);
	   showUploadedFilesList("scrappingFinalReportUrl", <%=HtmlUtil.arrayFromJavaToJavaScript(scrappingFinalFiles)%>);
   });
   </script>
   
   <%}%>
   <script>   
      
      <%String dest = request.getParameter(Default.SEARCH_DEST_PARAM_NAME);%>
      appendIdElement("<%=Default.SEARCH_DEST_PARAM_NAME%>","<%=dest%>");
      
   </script>
</body>
</html>